import {
	createWebHistory,
	createRouter
} from 'vue-router';

import routers from "./routers/routers.js";
import routePlus from "./route-plus.js";

const router = createRouter({
	history: createWebHistory(),
	routes: filterRouter(routers)
});

routePlus(router);

function filterRouter(routes) {
	if (!routes || routes.length < 1) {
		return;
	}
	let res = [];
	routes.forEach(item => {
		item.children = filterRouter(item.children);
		if (item.component || item.redirect) {
			res.push(item);
		} else {
			res = [...res, ...item.children];
		}
	})
	return res;
}

export default router;
